package com.aaa.controller.front;

import com.aaa.entity.*;
import com.aaa.service.front.ICollectService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RequestMapping("/front")
@Controller
public class CollectController {

    @Resource
    private ICollectService collectService;

    //收藏
    @RequestMapping("/wishlist")
    public String wishlist(HttpSession session,Collect collect){
        FrontUserinfo f=(FrontUserinfo) session.getAttribute("FrontUserinfo");

        if (f!=null){
            collect.setUserInfoId(f.getUserInfoId());
        }
        int collectId = collectService.doAddCollectGoods(collect);
        collect.setCollectId(collectId);

        return "redirect:/front/index";
    }

//我的收藏
@RequestMapping("/userCollection")
public String userCollection(Model model,HttpSession session){

    FrontUserinfo f=(FrontUserinfo) session.getAttribute("FrontUserinfo");
    Integer UserInfoId = f.getUserInfoId();
    List<Collect> collectList=collectService.findAllByCollect(UserInfoId);
    model.addAttribute("collectList",collectList);
    return "/front/wish-list";
}
    //删除收藏
    @RequestMapping("/userCollectionDelete")
    public String userCollectionDelete(Integer collectId){
        collectService.doDeleteByCollect(collectId);
        return "redirect:/front/userCollection";
    }


}
